#include "PrecompiledHeader.h"
#include "CSettings.h"

/*--------------------------------------------------------------------------*/
CSettings* g_Settings = NULL;
/*--------------------------------------------------------------------------*/

CSettings::CSettings() :
	IEngMod("CSettings"),
	m_maxThreads(1),
	m_fullscreenEnabled(false),
	m_resolutionf(glm::vec2(800.0f, 600.0f)),
	m_resolutioni(glm::vec2(800, 600)),
	m_vsyncEnabled(false)
{
	this->LoadConfig("../Binaries/config.xml");
}

/*--------------------------------------------------------------------------*/

CSettings::~CSettings()
{

}

/*--------------------------------------------------------------------------*/

void CSettings::LoadConfig(const std::string& path)
{
	XMLFile* config = (XMLFile*) FileSys::GetFile("config.xml");

	if (config)
	{
		pugi::xml_document& configxml = config->GetXMLDocument();

		this->m_maxThreads = configxml.child("config").child("engine").child("multithread").attribute("threads").as_uint(1);
		AssertLogC(this->m_maxThreads < 1, "Wrong maxthreads value: %d", this->m_maxThreads);
		AssertLogC(this->m_maxThreads > 8, "High number of additional threads! Are you sure?");

		this->m_resolutionf.x = configxml.child("config").child("engine").child("window").attribute("resx").as_float(800.0f);
		this->m_resolutionf.y = configxml.child("config").child("engine").child("window").attribute("resy").as_float(600.0f);

		this->m_resolutioni.x = configxml.child("config").child("engine").child("window").attribute("resx").as_int(800);
		this->m_resolutioni.y = configxml.child("config").child("engine").child("window").attribute("resy").as_int(600);

		this->m_vsyncEnabled = configxml.child("config").child("engine").child("window").attribute("vsync").as_bool(false);
		this->m_fullscreenEnabled = configxml.child("config").child("engine").child("window").attribute("fullscreen").as_bool(false);
		this->m_splashscreenEnabled = configxml.child("config").child("engine").child("splashscreen").attribute("enabled").as_bool(true);
	}
}

/*--------------------------------------------------------------------------*/

const glm::vec2& CSettings::GetResolutionf() const
{
	return this->m_resolutionf;
}

/*--------------------------------------------------------------------------*/

const glm::ivec2& CSettings::GetResolutioni() const
{
	return this->m_resolutioni;
}

/*--------------------------------------------------------------------------*/

bool CSettings::GetFullscreenEnabled() const
{
	return this->m_fullscreenEnabled;
}

/*--------------------------------------------------------------------------*/

int CSettings::GetMaxThreadsCount() const
{
	return this->m_maxThreads;
}

/*--------------------------------------------------------------------------*/

bool CSettings::GetSplashscreenEnabled() const
{
	return this->m_splashscreenEnabled;
}

/*--------------------------------------------------------------------------*/

bool CSettings::GetVSyncEnabled() const
{
	return this->m_vsyncEnabled;
}

/*--------------------------------------------------------------------------*/
